from contextlib import asynccontextmanager

from fastapi import FastAPI

from api import room
from api import user


@asynccontextmanager
async def lifespan(app: FastAPI):
    _ = app
    from db.database import async_engine, Base
    async def init_create_table():
        async with async_engine.begin() as conn:
            # await conn.run_sync(Base.metadata.drop_all)
            await conn.run_sync(Base.metadata.create_all)

    await init_create_table()
    yield


app = FastAPI(openapi_url="/api/v1/openapi.json", lifespan=lifespan)
# 注册路由

app.include_router(user.router_user)
app.include_router(room.router_char)


def create_app():
    return app
